<?php
function  studentImportExcel_RAW($ExlData){   // 将导入表中的数据添加到  数据库数组中去
    $Hint = new \Operation\Controller\HintController();     // 生成操作类对象
    for($i = 2,$j=0;$i<sizeof($ExlData);$i++,$j++){
        $dataList[] = array(
            'username'=>$ExlData[$i]['A'],
            'pwd'     =>MD5(11),
            'realname'=>$ExlData[$i]['B'],
            'stunum'  =>$ExlData[$i]['C'],
            'email'   =>$ExlData[$i]['D'],
            'phone'   =>$ExlData[$i]['E'],
            'photo'   =>$Hint->randPhoto(),
            'role'    =>'1',
            'intro'   =>'这家伙很懒什么都没留下',
            'regdate' =>date('Y-m-d H:i:s', time())         // 写入注册时间
        );
    }
    return $dataList;
}


function derived_excel($all_project_information){
    
        import("Org.Util.PHPExcel");
        import("Org.Util.PHPExcel.Writer.Excel2007");
        import("Org.Util.PHPExcel.Writer.Excel5");
        import("Org.Util.PHPExcel.IOFactory");
        
        $objPHPExcel = new \PHPExcel();
        // 设置表头
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.'1', '编号')
                                            ->setCellValue('B'.'1', '项目名称')
                                            ->setCellValue('C'.'1', '用户名')
                                            ->setCellValue('D'.'1', '项目类型')
                                            ->setCellValue('E'.'1', '项目类别')
                                            ->setCellValue('F'.'1', '所属团队')
                                            ->setCellValue('G'.'1', '负责人')
                                            ->setCellValue('H'.'1', '是否招标')
                                            ->setCellValue('I'.'1', '发布时间')
                                            ->setCellValue('J'.'1', '项目状态')
                                            ->setCellValue('K'.'1', '是否通过')
                                            ->setCellValue('L'.'1', '招标要求')
                                            ->setCellValue('M'.'1', '点击量')
                                            ->setCellValue('N'.'1', '成果说明')
                                            ->setCellValue('O'.'1', '中标人员信息')
                                            ->setCellValue('P'.'1', '研究内容');
        // 屌丝的设计： 设置单格宽度，不能再一个里面写，  setWidth 即为设置 固定长度    setAutoSize 即为自动但是有时不准
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(5);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('D')->setWidth(8);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('E')->setWidth(12);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('F')->setWidth(17);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('G')->setWidth(8);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('H')->setWidth(9);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('I')->setWidth(17);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('J')->setWidth(9);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('K')->setWidth(8);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('L')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('M')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('N')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('O')->setAutoSize(true);
        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('P')->setAutoSize(true);
        // 循环输出数据到excel对应的位置
        foreach($all_project_information as $k => $v){
            
            $num=$k+2;
            switch ($v['isbid']){
                case 0: $isbid = "不招标"; break;
                case 1: $isbid = "招标中"; break;
                case 2: $isbid = "停止招标"; break;
            }
            switch ($v['ischecked']){
                case 0: $ischecked = "未审核"; break;
                case 1: $ischecked = "审核通过"; break;
                case 2: $ischecked = "审核未通过"; break;
            }
            
            $objPHPExcel->setActiveSheetIndex(0) 
                        ->setCellValue('A'.$num, $num-1)
                        ->setCellValue('B'.$num, $v['name'])
                        ->setCellValue('C'.$num, $v['isuser'])
                        ->setCellValue('D'.$num, $v['typename'])
                        ->setCellValue('E'.$num, $v['categoryname'])
                        ->setCellValue('F'.$num, $v['teamname'])
                        ->setCellValue('G'.$num, $v['leader'])
                        ->setCellValue('H'.$num, $isbid)
                        ->setCellValue('I'.$num, $v['adddate'])
                        ->setCellValue('J'.$num, $v['pstate'])
                        ->setCellValue('K'.$num, $ischecked)
                        ->setCellValue('L'.$num, $v['bidinfo'])
                        ->setCellValue('M'.$num, $v['rate'])
                        ->setCellValue('N'.$num, $v['explain'])
                        ->setCellValue('O'.$num, $v['group_concat( users.stunum, users.realname, users.phone )'])
                        ->setCellValue('P'.$num, strip_tags($v['intro']));
        }
        // 详细解释见Home 下的function.php 底段注释
        $this_time = date('Y-m-d', time());
        $objPHPExcel->getActiveSheet()->setTitle("$this_time");
        $objPHPExcel->setActiveSheetIndex(0);
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="'.$this_time._全部导出数据.'.xls"');
        header('Cache-Control: max-age=0');
        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;
    
}
function getpage($count, $pagesize) {
    $p = new Think\Page($count, $pagesize);
    $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
    $p->setConfig('prev', '上一页');
    $p->setConfig('next', '下一页');
    $p->setConfig('last', '末页');
    $p->setConfig('first', '首页');
    $p->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
    $p->lastSuffix = false;//最后一页不显示为总页数
    return $p;
}